package t01;

public class Pi {
    public static void calculate() {
        int i = 1;// 分母的一部分
        double n = 1;// 控制循环次数
        int sign = 1;// 1 or -1
        double pi = 0;
        while (Math.abs(n) >= 1e-5) {
            pi += sign * 4.0 / i;
            sign = -1 * sign;
            i += 2;
            n = 4.0 / i;
        }
        System.out.println("The value of pi is approximately: " + pi);
    }

    public static void main(String[] args) {
        calculate();
    }
}
